package com.zyz.N_反射机制.基本应用.创建运行时类的对象;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author: vick
 * @Date: 2025/4/14
 * @Description:
 * @version: 1.0
 */
public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //获取class对象
        Class<?> clazz = Class.forName("com.vick.N_反射机制.基本应用.创建运行时类的对象.Person");

        //获取指定构造器对象, 包括 private
        Constructor<?> declaredConstructor = clazz.getDeclaredConstructor(String.class, int.class);
        Object object = declaredConstructor.newInstance("vick", 22);
        System.out.println(object);
    }
}
